package com.dyc.caradvertisting.ui.fmt.tab.mine;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.allen.supertextviewlibrary.SuperTextView;
import com.dyc.caradvertisting.R;
import com.dyc.caradvertisting.base.BaseLazyMainFragment;
import com.dyc.caradvertisting.event.StartBrotherEvent;
import com.dyc.caradvertisting.ui.aty.yd.YDActivity;
import com.dyc.caradvertisting.ui.fmt.pay.AssetFmt;
import com.dyc.caradvertisting.ui.fmt.pay.PayFmt;
import com.dyc.caradvertisting.ui.fmt.about.AboutFmt;
import com.dyc.caradvertisting.ui.fmt.bind.BindSetListFmt;
import com.dyc.caradvertisting.ui.fmt.tab.mine.details.MineDetailsFmt;
import com.dyc.caradvertisting.ui.fmt.tab.mine.location.LocationFmt;
import com.dyc.caradvertisting.ui.fmt.tab.smsg.SystemMesFmt;
import com.njh.tools.api.manager.RetrofitManager;
import com.njh.tools.common.img.GlideUtils;
import com.njh.tools.common.phone.ToActivityUtil;
import com.njh.tools.common.userInfo.SPUserInfo;

import org.greenrobot.eventbus.EventBus;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 个人中心
 */
public class MineFragment extends BaseLazyMainFragment implements View.OnClickListener {


    @BindView(R.id.img_client)
    ImageView imgClient;
    @BindView(R.id.stv_about_mine)
    SuperTextView stvAboutMine;
    @BindView(R.id.tv_nicke)
    TextView tvNicke;
    @BindView(R.id.stv_nobuliding)
    SuperTextView stvNobuliding;
    @BindView(R.id.stv_location)
    SuperTextView stvLocation;
    @BindView(R.id.stv_off_adv)
    SuperTextView stvOffAdv;
    @BindView(R.id.stv_my_wallet)
    SuperTextView stvMyWallet;
    @BindView(R.id.stv_do_guide)
    SuperTextView stvDoGuide;
    @BindView(R.id.tv_df_message)
    TextView tvDfMessage;
    @BindView(R.id.tv_qf_message)
    TextView tvQfMessage;
    @BindView(R.id.tv_jb_message)
    TextView tvJbMessage;

    public static MineFragment newInstance() {
        MineFragment fragment = new MineFragment();
        Bundle args = new Bundle();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public int getLayoutId() {
        return R.layout.fragment_client;
    }

    @Override
    public void initView(View baseView) {
        ButterKnife.bind(this, baseView);
        initToolbar(R.string.title_mine);
        imgClient.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (SPUserInfo.getIsLogin(MineFragment.this.getContext())){
                    EventBus.getDefault().post(new StartBrotherEvent(MineDetailsFmt.newInstance()));
                }
            }
        });
        stvAboutMine.setOnClickListener(this);
        if (SPUserInfo.getIsLogin(this.getContext())) {
            GlideUtils.displayImageCircle(this.getContext(),
                    RetrofitManager.baseUrl + SPUserInfo.getHeadurl(this.getContext()), imgClient);
            setTextValue(tvNicke, SPUserInfo.getPhone(this.getContext()));
//        setTextValue(tvDfMessage,UserInfoUtils.get);
        }
        setHasOptionsMenu(true);
        ((AppCompatActivity) getActivity()).setSupportActionBar(toolbar);
        stvNobuliding.setLeftTopTVColor(R.color.red_normal);
    }

    @Override
    public boolean isSwipeBack() {
        return false;
    }
    @Override
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        menu.clear();
        inflater.inflate(R.menu.menu_parent_fragment, menu);
    }
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.action_android://我的系统消息
                // 这里我使用EventBus通知父MainFragment处理跳转(接耦),
                EventBus.getDefault().post(new StartBrotherEvent(SystemMesFmt.newInstance()));
//                Log.i(TAG, "action android selected");
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }
    @Override
    public void initPresenter() {

    }

    @Override
    public void onHiddenChanged(boolean hidden) {
        super.onHiddenChanged(hidden);
        if (!hidden)
        if (null!=imgClient) {
            GlideUtils.displayImageCircle(this.getContext(),
                    RetrofitManager.baseUrl+SPUserInfo.getHeadurl(this.getContext()), imgClient);
            setTextValue(tvNicke, SPUserInfo.getPhone(this.getContext()));
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        ButterKnife.bind(this, getView(inflater, container));
        return getView(inflater, container);
    }

    @Override
    protected void initLazyView(@Nullable Bundle savedInstanceState) {

    }

    @OnClick({R.id.stv_nobuliding,
            R.id.stv_location,
            R.id.stv_off_adv,
            R.id.stv_my_wallet,
            R.id.stv_about_mine,
            R.id.stv_do_guide})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.stv_nobuliding:
                // 这里我使用EventBus通知父MainFragment处理跳转(接耦),
                EventBus.getDefault().post(new StartBrotherEvent(BindSetListFmt.newInstance()));
                break;
            case R.id.stv_location:
                // 这里我使用EventBus通知父MainFragment处理跳转(接耦),
                EventBus.getDefault().post(new StartBrotherEvent(LocationFmt.newInstance()));
                break;
            case R.id.stv_off_adv:
                break;
            case R.id.stv_my_wallet:
                // 这里我使用EventBus通知父MainFragment处理跳转(接耦),
                EventBus.getDefault().post(new StartBrotherEvent(AssetFmt.newInstance()));
                break;
            case R.id.stv_about_mine://关于我们
                // 这里我使用EventBus通知父MainFragment处理跳转(接耦),
                EventBus.getDefault().post(new StartBrotherEvent(AboutFmt.newInstance()));
                break;
            case R.id.stv_do_guide://引导界面
                ToActivityUtil.getInstance().toNext(MineFragment.this._mActivity, YDActivity.class);
                break;
        }
    }
}
